package java_09_13;


import java.util.*;

/*
昨天字符排序的那个
*/
public class Test_1 {
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        System.out.println("请输入一个字符");
        String s = in.next();
        Map<Object, Integer> m = new HashMap<>();
        for (int i=0;i<s.length();i++){
            char c=s.charAt(i);
            if (m.containsKey(c)){
                m.put(c,m.get(c)+1);
            }else{
                m.put(c,1);
            }
        }
        System.out.println(m);
        Set<Map.Entry<Object, Integer>> entries = m.entrySet();
       List<Map.Entry<Object, Integer>> list= new  ArrayList<>();
       list.addAll(entries);
       Collections.sort(list, new Comparator<Map.Entry<Object, Integer>>() {
           @Override
           public int compare(Map.Entry<Object, Integer> o1, Map.Entry<Object, Integer> o2) {
               return o2.getValue()- o1.getValue();
           }
       });
       for (Map.Entry<Object, Integer> x:list){
           System.out.println(x.getKey()+""+x.getValue());
       }
    }
}
